/*--------------------------------------------------------------------------
ASSERT.H

Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/

#ifndef __ASSERT_H__
#define __ASSERT_H__

#undef assert

/*
#ifndef	__ASSERT_INC
#include <stdio.h>
#define	__ASSERT_INC
#endif
*/
#include "c51_rs232.h"

#ifndef NDEBUG

#define DB_CHAR(a)    do{putchark((a));}while(0)
#define DB_CRLF()     do{ putCRLF();}while(0)
#define DB_STRING(k)  do{printk((k));}while(0)
#define DB_STRINGLN(k)  do{printlnk((k)); }while(0)

#define DB_6CHAR(a0,a1,a2,a3,a4,a5)  \
        do{\
            putchark((a0));\
            putchark((a1));\
            putchark((a2));\
            putchark((a3));\
            putchark((a4));\
            putchark((a5));\
        }while(0)
#define DB_6DIGIT(a) \
        DB_6CHAR((a)%1000000/100000+'0',   \
                 (a)%100000/10000+'0',   \
                 (a)%10000/1000+'0',   \
                 (a)%1000/100+'0',   \
                 (a)%100/10+'0',   \
                 (a)%10+'0')


#define assert(expr) \
  if (expr) { ; } \
  else  {\
    printk("Assert failed: ");\
    printk(#expr);\
    putchark(' ');\
    printk(__FILE__);\
    putchark(' ');\
    putchark('L');\
    DB_6DIGIT((int)__LINE__);\
    putCRLF();\
  }

//printf("Assert failed: " #expr " (file %s line %d)\n", __FILE__, (int) __LINE__ );

#else
#define	assert(expr)

#define DB_STRING(k)
#define DB_6CHAR(a0,a1,a2,a3,a4,a5)
#define DB_CHAR(a)
#define DB_CRLF()
#define DB_6DIGIT(a)
#define DB_STRINGLN(k)
#endif



#endif
